home *** CD-ROM | disk | FTP | other *** search
- Listing 2 - a test program for generic queues based on the generic.h
- macros
-
- //
- // strtst7.cpp - test gueue(str)
- //
-
- #include <iostream.h>
-
- #include "queue7.h"
- #include "showheap.h"
- #include "str.h"
-
- declare(queue, str)
-
- ostream &operator<<(ostream &os, queue(str) &q)
- {
- str *ps;
- queue(str)::iterator sqi(q);
- while ((ps = sqi.next()) != 0)
- os << ' ' << *ps;
- return os;
- }
-
- #define DIM(a) (sizeof(a)/sizeof(a[0]))
-
- void test()
- {
- char c;
- size_t qn;
- str qe;
- queue(str) q[4];
- while (cin >> c)
- {
- showheap();
- if (c == 'q')
- break;
- if (c == 'a')
- {
- cin >> qn >> qe;
- if (qn >= DIM(q))
- cout << "no such queue\n";
- else
- q[qn].append(qe);
- }
- else if (c == 'c')
- {
- cin >> qn;
- if (qn >= DIM(q))
- cout << "no such queue\n";
- else
- q[qn].clear();
- }
- else if (c == 'r')
- {
- cin >> qn;
- if (qn >= DIM(q))
- cout << "no such queue\n";
- else if (q[qn].remove(qe))
- cout << "removed " << qe << '\n';
- else
- cout << "q[" << qn << "] is empty\n";
- }
- else
- continue;
- for (size_t i = 0; i < DIM(q); ++i)
- cout << i << ':' << q[i] << '\n';
- }
- }
-
- int main()
- {
- showheap();
- test();
- showheap();
- return 0;
- }
-
-